﻿package media 
{
	
	import debugs.Debug;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	/**
	 * ...
	 * @author keys_star@163.com
	 */
	public class soundItem extends EventDispatcher
	{
		public var soundArr:Array;
		private var mys:sound;
		public var id:uint = 0;
		public function soundItem() 
		{
			soundArr = new Array;
		}
		public function init() {
			id = 0;
		}
		public function play() {
			mys = new sound(soundArr[id]+".mp3");
			mys.addEventListener(Event.SOUND_COMPLETE, com);
			mys.play();
			dispatchEvent(new Event(Event.CHANGE));
			id++;
		}
		private function com(e:Event) {
			if (id < soundArr.length) {
				//Debug.send(this + ".nextsound.");
				play();
			}else {
				Debug.send(this + ".allcom.");
				dispatchEvent(e);
			}
		}
		public function stop() {
			mys.stop();
			mys.removeEventListener(Event.SOUND_COMPLETE, com);
		}
	}
}